

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/boshi.jpeg">
  <link rel="icon" type="image/png" href="/img/boshi.jpeg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="wangpf">
  <meta name="keywords" content="">
  <title>webpack - wpf的博客</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/foundation.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_6peoq002giu.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.1.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Wangpf's blog</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/article.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2020-09-25 16:13" pubdate>
      2020年9月25日 下午
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.6k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      19
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">webpack</h1>
            
            <div class="markdown-body" id="post-body">
              <h1 id="webpack⭐"><a href="#webpack⭐" class="headerlink" title="webpack⭐"></a>webpack⭐</h1><h2 id="1-什么是webpack？"><a href="#1-什么是webpack？" class="headerlink" title="1 什么是webpack？"></a>1 什么是webpack？</h2><ul>
<li>官方解释： At its core, webpack is a static module bundler for modern JavaScript applications.</li>
<li>翻译： 从本质上来讲，webpack 是一个现代的JavaScript应用的静态<strong>模块打包</strong>工具</li>
</ul>
<p><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3378498490,2105022646&fm=26&gp=0.jpg" srcset="/img/loading.gif" alt="img"></p>
<h3 id="1-1-模块"><a href="#1-1-模块" class="headerlink" title="1.1 模块"></a>1.1 模块</h3><ul>
<li>前端模块化：</li>
<li>目前使用前端模块化的一些方案：AMD、CMD、CommonJS、ES6。</li>
<li>在ES6之前，我们要想进行模块化开发，就必须借助于其他的工具，让我们可以进行模块化开发。</li>
<li>并且在通过模块化开发完成了项目后，还需要处理模块间的各种依赖，并且将其进行整合打包。</li>
<li>而webpack其中一个<strong>核心就是让我们可能进行模块化开发，并且会帮助我们处理模块间的依赖关系</strong>。</li>
<li>而且不仅仅是JavaScript文件，我们的CSS、图片、json文件等等在webpack中都可以被当做模块来使用</li>
<li>这就是webpack中模块化的概念。</li>
</ul>
<h3 id="1-2-打包"><a href="#1-2-打包" class="headerlink" title="1.2 打包"></a>1.2 打包</h3><ul>
<li>就是将webpack中的各种资源模块进行打包合并成一个或多个包(Bundle)。</li>
<li>并且在打包的过程中，还可以对资源进行处理，比如压缩图片，将scss转成css，将ES6语法转成ES5语法，将TypeScript转成JavaScript等等操作。</li>
<li>但是打包的操作似乎grunt/gulp也可以帮助我们完成，它们有什么不同呢？</li>
</ul>
<h3 id="1-3-和grunt-gulp的对比"><a href="#1-3-和grunt-gulp的对比" class="headerlink" title="1.3 和grunt/gulp的对比"></a>1.3 和grunt/gulp的对比</h3><ul>
<li>grunt/gulp的核心是<strong>Task</strong><ul>
<li>我们可以配置一系列的task，并且定义task要处理的事务（例如ES6、ts转化，图片压缩，scss转成css）</li>
<li>之后让grunt/gulp来依次执行这些task，而且让整个流程自动化。</li>
<li>所以grunt/gulp也被称为前端自动化任务管理工具。</li>
</ul>
</li>
</ul>
<ul>
<li>什么时候用grunt/gulp呢？<ul>
<li>如果你的工程模块依赖非常简单，甚至是没有用到模块化的概念。</li>
<li>只需要进行简单的合并、压缩，就使用grunt/gulp即可。</li>
<li>但是如果整个项目使用了模块化管理，而且相互依赖非常强，我们就可以使用更加强大的webpack了。</li>
</ul>
</li>
</ul>
<ul>
<li>grunt/gulp和webpack有什么不同呢？<ul>
<li>grunt/gulp更加强调的是前端流程的自动化，模块化不是它的核心。</li>
<li>webpack更加强调模块化开发管理，而文件压缩合并、预处理等功能，是他附带的功能。</li>
</ul>
</li>
</ul>
<h2 id="2-webpack的安装"><a href="#2-webpack的安装" class="headerlink" title="2  webpack的安装"></a>2  webpack的安装</h2><ul>
<li><p>安装webpack首先需要安装Node.js，Node.js自带了软件包管理工具npm<br>查看自己的node版本：</p>
<div class="hljs"><pre><code class="hljs shell">node -v</code></pre></div>



</li>
</ul>
<ul>
<li><p>全局安装webpack(这里我先指定版本号3.6.0，因为vue cli2依赖该版本)</p>
<div class="hljs"><pre><code class="hljs shell">npm install webpack@3.6.0 -g</code></pre></div>
</li>
<li><p>局部安装 webpack</p>
</li>
</ul>
<div class="hljs"><pre><code class="hljs shell"><span class="hljs-meta">#</span><span class="bash"><span class="hljs-comment"># 在对应目录下执行该命令</span></span>
npm install webpack@3.6.0  --save-dev
<span class="hljs-meta">#</span><span class="bash"><span class="hljs-comment">#  因为webpack我们项目打包后不需要使用 ， 所以它只是我们开发时的一个工具  --save-dev  是开发时依赖</span></span></code></pre></div>

<ul>
<li><p>全局安装和局部安装的区别</p>
<ul>
<li>在终端直接执行的webpack命令，使用的是全局安装的webpack</li>
<li>当在packag.json中定义了scripts时，其中包含了webpack命令，那么使用的是局部webpack</li>
</ul>
<div class="hljs"><pre><code class="hljs json">&quot;scripts&quot;: &#123;
   &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,
   &quot;bulid&quot;: &quot;webpack&quot;
 &#125;,</code></pre></div>



</li>
</ul>
<h2 id="3-webpack的配置"><a href="#3-webpack的配置" class="headerlink" title="3 webpack的配置"></a>3 webpack的配置</h2><h3 id="3-1-入口和出口"><a href="#3-1-入口和出口" class="headerlink" title="3.1 入口和出口"></a>3.1 入口和出口</h3><ul>
<li>如果每次使用webpack的命令都需要写上入口和出口作为参数，就很麻烦。</li>
<li>我们要创建一个 webpack.config.js文件</li>
</ul>
<p><img src="https://i.loli.net/2020/09/25/Pk7tDBJoyAeibQr.png" srcset="/img/loading.gif" alt="image-20200922173645764"></p>
<h3 id="3-2-如何使用局部安装的webpack"><a href="#3-2-如何使用局部安装的webpack" class="headerlink" title="3.2 如何使用局部安装的webpack"></a>3.2 如何使用局部安装的webpack</h3><h5 id="方法一："><a href="#方法一：" class="headerlink" title="方法一："></a>方法一：</h5><ul>
<li>第一步：项目中需要安装自己局部的webpack<ul>
<li>这里我们让局部安装   <a href="mailto:&#x77;&#x65;&#98;&#x70;&#x61;&#99;&#107;&#x40;&#x33;&#x2e;&#54;&#46;&#48;">&#x77;&#x65;&#98;&#x70;&#x61;&#99;&#107;&#x40;&#x33;&#x2e;&#54;&#46;&#48;</a> （因为我们要使用 脚手架2版本来学习）</li>
<li>Vue CLI3中已经升级到webpack4，但是它将配置文件隐藏了起来，所以查看起来不是很方便。</li>
</ul>
</li>
<li>第二步，通过node_modules/.bin/webpack启动webpack打包</li>
</ul>
<h5 id="方法二："><a href="#方法二：" class="headerlink" title="方法二："></a>方法二：</h5><ul>
<li>但是，每次执行都敲这么一长串有没有觉得不方便呢？<ul>
<li>OK，我们可以在package.json的scripts中定义自己的执行脚本。</li>
</ul>
</li>
<li>package.json中的scripts的脚本在执行时，会按照一定的顺序寻找命令对应的位置。<ul>
<li>首先，会寻找本地的node_modules/.bin路径中对应的命令。</li>
<li>如果没有找到，会去全局的环境变量中寻找。</li>
<li>如何执行我们的build指令呢？   <code>npm run bulid</code></li>
</ul>
</li>
<li><img src="https://i.loli.net/2020/09/26/RItGULf3edK1VSc.png" srcset="/img/loading.gif" alt="image-20200922174156285"></li>
</ul>
<h2 id="4-webpack-loader加载器"><a href="#4-webpack-loader加载器" class="headerlink" title="4 webpack-loader加载器"></a>4 webpack-loader加载器</h2><blockquote>
<p><strong>loader是webpack中一个非常核心的概念。</strong></p>
</blockquote>
<ul>
<li><p>webpack用来做什么呢？</p>
<ul>
<li><p>在我们之前的实例中，我们主要是用webpack来处理我们写的js代码，并且webpack会自动处理js之间相关的依赖。</p>
</li>
<li><p>但是，在开发中我们不仅仅有基本的js代码处理，我们也需要加载css、图片，也包括一些高级的将ES6转成ES5代码，将</p>
<p>TypeScript转成ES5代码，将scss、less转成css，将.jsx、.vue文件转成js文件等等。</p>
</li>
<li><p>对于webpack本身的能力来说，对于这些转化是不支持的。</p>
</li>
<li><p>那怎么办呢？给webpack扩展对应的loader就可以啦。</p>
</li>
</ul>
</li>
<li><p>loader使用过程：</p>
<ul>
<li>步骤一：通过npm安装需要使用的loader</li>
<li>步骤二：在webpack.config.js中的modules关键字下进行配置</li>
</ul>
</li>
<li><p>大部分loader我们都可以在webpack的官网中找到，并且学习对应的用法。</p>
</li>
</ul>
<p>webpack.config.js 文件如下：  <strong>如何配置 响应的 loader 在module内</strong></p>
<div class="hljs"><pre><code class="hljs JSON">const path = require(&#x27;path&#x27;)

module.exports = &#123;
  entry: &#x27;./src/main.js&#x27;,
  output: &#123;
    path: path.resolve(__dirname, &#x27;dist&#x27;),
    filename: &#x27;bundle.js&#x27;,
    publicPath: &#x27;dist/&#x27;
  &#125;,
  module: &#123;
    rules: [&#123;
        test: /\.css$/,
        <span class="hljs-comment">// style-loader 负责将样式添加到DOM中</span>
        <span class="hljs-comment">// css-loader 负责将css文件进行加载</span>
        <span class="hljs-comment">// 注意：  使用多个 loader时， webpack是从右向左解析的</span>
        use: [&#x27;style-loader&#x27;, &#x27;css-loader&#x27;]
      &#125;,
      &#123;
        test: /\.(png|jpg|gif)$/,
        use: [&#123;
          loader: &#x27;file-loader&#x27;,
          options: &#123;
            name: &#x27;img/[name].[hash:8].[ext]&#x27;
          &#125;
        &#125;]
      &#125;,
      &#123;
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: &#123;
          loader: &#x27;babel-loader&#x27;,
          options: &#123;
            presets: [&#x27;es2015&#x27;]
          &#125;
        &#125;
      &#125;
    ]
  &#125;
&#125;</code></pre></div>





<h2 id="5-webpack插件-plugin"><a href="#5-webpack插件-plugin" class="headerlink" title="5 webpack插件   plugin"></a>5 webpack插件   plugin</h2><ul>
<li>plugin是什么？<ul>
<li>plugin是插件的意思，通常是用于对某个现有的架构进行扩展。</li>
<li>webpack中的插件，就是对webpack现有功能的各种扩展，比如打包优化，文件压缩等等。</li>
</ul>
</li>
<li>loader和plugin区别<ul>
<li>loader主要用于转换某些类型的模块，它是一个转换器。</li>
<li>plugin是插件，它是对webpack本身的扩展，是一个扩展器。</li>
</ul>
</li>
<li>plugin的使用过程：<ul>
<li>步骤一：通过npm安装需要使用的plugins(某些webpack已经内置的插件不需要安装)</li>
<li>步骤二：在webpack.config.js中的plugins中配置插件。</li>
</ul>
</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                <div class="post-meta mr-3">
                  <i class="iconfont icon-category"></i>
                  
                  <a class="hover-with-bg" href="/categories/vue/">vue</a>
                  
                </div>
                
                
                <div class="post-meta">
                  <i class="iconfont icon-tags"></i>
                  
                  <a class="hover-with-bg" href="/tags/vue/">vue</a>
                  
                </div>
                
              </div>
              
              
              <div class="post-prevnext row">
                <article class="post-prev col-6">
                  
                  
                  <a href="/2020/09/26/22-Vue-Cli%E8%84%9A%E6%89%8B%E6%9E%B6/">
                    <i class="iconfont icon-arrowleft"></i>
                    <span class="hidden-mobile">Vue-Cli脚手架</span>
                    <span class="visible-mobile">上一篇</span>
                  </a>
                  
                </article>
                <article class="post-next col-6">
                  
                  
                  <a href="/2020/09/25/20-vue%E6%8F%92%E6%A7%BD/">
                    <span class="hidden-mobile">vue插槽</span>
                    <span class="visible-mobile">下一篇</span>
                    <i class="iconfont icon-arrowright"></i>
                  </a>
                  
                </article>
              </div>
              
            </div>

            
            <!-- Comments -->
            <article class="comments" id="comments">
              
              
  <div id="vcomments"></div>
  <script type="text/javascript">
    function loadValine() {
      addScript('https://cdn.staticfile.org/valine/1.4.14/Valine.min.js', function () {
        new Valine({
          el: "#vcomments",
          app_id: "hjxsDRXYScicliqD8I8JqoTu-gzGzoHsz",
          app_key: "qUcAEReEqeEVp5wwXJ41uCCp",
          placeholder: "说点什么",
          path: window.location.pathname,
          avatar: "retro",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: true,
          recordIP: false,
          serverURLs: "",
        });
      });
    }
    waitElementVisible('vcomments', loadValine);
  </script>
  <noscript>Please enable JavaScript to view the <a target="_blank" href="https://valine.js.org" rel="nofollow noopener noopener">comments
      powered by Valine.</a></noscript>


            </article>
            
          </article>
        </div>
      </div>
    </div>
    
    <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
      <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

    </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    
      <script  src="/js/lazyload.js" ></script>
    
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "webpack&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "always",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  











  

  

  

  

  

  





</body>
</html>
